﻿@{
    ViewBag.Title = "系统配置";
    Layout = "~/Views/Shared/_Main.cshtml";
}
<style>
    select
    {
        width: 90px;
    }
</style>
<script type="text/javascript">
    $(function () {
        $.post("/PEPara/GetSysConfig", { type: 1 }, function (res) {
            for (var i = 0; i < res.length; i++) {
                $("#txt_" + res[i].KeyName).val(res[i].KeyValue);
            }
        });
        $.post("/PEPara/GetSysConfig", { type: 4 }, function (res) {
            for (var i = 0; i < res.length; i++) {
                $("#txt_IFName").val(res[i].KeyValue);
            }
        });
        $.post("/PEPara/GetDBDriverConfig", function (res) {
            dbDriver = res;
            for (var i = 0; i < res.length; i++) {
                $("#sel_DBConfigName").append("<option value='" + res[i].DBType + "'>" + res[i].DBConfigName + "</option>");
            }
            if (res.length > 0) {
                jv.SetDivJson($(".DBDriverConfig"), 4, res[0]);
                $("#sel_DBConfigName").val(res[0].DBType);
            }
        });
    });
    var dbDriver = new Array();
    function ChangeDB(v) {
        var index = 0;
        for (var i = 0; i < dbDriver.length; i++) {
            if (dbDriver[i].DBType == v)
                index = i;
        }
        jv.SetDivJson($(".DBDriverConfig"), 4, dbDriver[index]);
        $("#sel_DBConfigName").val(dbDriver[index].DBType);
    }
    function save() {
        $.post("/PEPara/SaveSysConfig", { TimeOut: checkNum($.trim($("#txt_TimeOut").val())), TimeOutLot: checkNum($.trim($("#txt_TimeOutLot").val())) }, function (res) {
            if (res == "1")
                alert("操作成功！");
            else
                alert(res);
        });
    }
    function saveIF() {
        $.post("/PEPara/SaveSysConfigIFName", { IFName: $.trim($("#txt_IFName").val()) }, function (res) {
            if (res == "1")
                alert("操作成功！");
            else
                alert(res);
        });
    }
    function saveRetry() {
        $.post("/PEPara/SaveSysConfigRetry", { Retry: checkNum($.trim($("#txt_RetryNum").val())) }, function (res) {
            if (res == "1")
                alert("操作成功！");
            else
                alert(res);
        });
    }
    function save2() { }
    function save3() {
        $.post("/PEPara/SaveDBDriverConfig", { query: jv.GetDivJson($(".DBDriverConfig"), 4) }, function (res) {
            if (res == "1")
                alert("操作成功！");
            else
                alert(res);
        });
    }
</script>
<script type="text/javascript">
    $(function () {
        $("#DataGrid").dg(optsIF);
    });
    var optsIF = {
        rows: 10,
        height: 450,
        url: "/SysUser/GetIFList",
        para: {},
        idField: "GUID",
        checkbox: false,
        columns: [
                    { field: 'IFName', title: '接口名称', width: 20 },
                    { field: 'IColumnName', title: '收件人', width: 10 },
                    { field: 'MsgContent', title: '消息内容', width: 25 },
                    { field: 'MinInterval', title: '最小发送间隔', align: 'center', width: 10 },
                    { field: 'Status', title: '接口状态', align: 'center', width: 10,
                        formatter: function (value, rowData, rowIndex) {
                            if (value == 1)
                                return "启用";
                            else
                                return "<font color='#ff0000'>禁用</font>";
                        }
                    },
                    { field: 'GUID', title: '操作', align: 'center', width: 10,
                        formatter: function (value, rowData, rowIndex) {
                            var doActionOptions = "<select onchange='return DoAction(this.options.selectedIndex,\"" + value + "\")' ><option value=''>-请选择-</option>";
                            doActionOptions += "<option>修改</option><option>删除</option>";
                            if (rowData.Status == 1)
                                doActionOptions += "<option>禁用</option>";
                            else
                                doActionOptions += "<option>启用</option>";
                            return doActionOptions + "</select>";
                        }
                    }
                    ]
    };
    //“操作”下拉框事件
    function DoAction(i, value) {
        if (i == 1) {
            EditFun(value); // 编辑
        }
        else if (i == 2) {
            DeleteFun(value); // 删除
        }
        else if (i == 3) {
            UpdateFun(value); // 启用禁用
        }
        $("#DataGrid").dg(optsIF);
    }

    function AddFun() {
        showModalMany('AddDB', '/SysUser/EditIF', '610', '250');
        $("#DataGrid").dg(optsIF);
    }

    function EditFun(funID) {
        showModalMany('AddDB', "/SysUser/EditIF?IFID=" + funID, '610', '250');
        $("#DataGrid").dg(optsIF);
    }
    function UpdateFun(funID) {
        $.post("/SysUser/UpdateFunStatus?ID=" + funID, function (res) {
            if (res == "1") {
                alert("操作成功！");
            }
            else {
                alert(res);
            }
            $("#DataGrid").dg(optsIF);
        });
    }
    function DeleteFun(funID) {
        if (confirm("确定要删除吗?")) {
            $.post("/SysUser/DeleteIF?IFID=" + funID, function (res) {
                if (res == 1) {
                    alert("操作成功！");
                }
                else {
                    alert(res);
                }
                $("#DataGrid").dg(optsIF);
            });
        }
    }
</script>
<div style="margin: 5px;">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/edit.png" />
            </td>
            <td width="300">
                超时配置
            </td>
            <td align="right">
                <input type="button" class="button" value="保存" onclick="save()" />
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td height="50">
                普通实例：<input type="text" id="txt_TimeOut" onkeyup="this.value=checkNum(this.value)" />
                (秒)<br />
                海量实例：<input type="text" id="txt_TimeOutLot" onkeyup="this.value=checkNum(this.value)" />
                (秒)
            </td>
        </tr>
    </table>
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/edit.png" />
            </td>
            <td width="300">
                外挂接口程序
            </td>
            <td align="right">
                <input type="button" class="button" value="保存" onclick="saveIF()" />
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td>
                程序名称：<input type="text" id="txt_IFName" maxlength="200" style="width:300px;"/>
            </td>
        </tr>
    </table>
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/edit.png" />
            </td>
            <td width="300">
                驱动程序配置
            </td>
            <td align="right">
                <input type="button" class="button" value="保存" onclick="save3()" />
            </td>
        </tr>
    </table>
    <table class="searchArea DBDriverConfig" width="100%">
        <tr>
            <td>
                数据库名：<select id="sel_DBConfigName" onchange="ChangeDB(this.value)"></select><br />
                连接顺序：<input type="text" id="txt_SortNum" onkeyup="this.value=checkNum(this.value)" /><br />
                连接类型：<select id="sel_ConnectionType"><option value="1">OLEDB</option>
                    <option value="2">ODBC</option>
                </select><br />
                驱动内容：<textarea id="txt_DBContent" style="width: 400px; height: 60px;"></textarea>
            </td>
        </tr>
    </table>
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/edit.png" />
            </td>
            <td width="300">
                消息接口配置列表
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    <table id="DataGrid" class="pagTable" cellpadding="0" cellspacing="0">
    </table>
</div>
